package win.acfelis.service.impl;

import org.springframework.stereotype.Service;
import win.acfelis.dao.UserMapper;
import win.acfelis.domain.UserInfo;
import win.acfelis.service.UserService;
import win.acfelis.tools.ApiResult;
import win.acfelis.tools.AppContent;
import win.acfelis.tools.MD5Utils;

import javax.annotation.Resource;

/**
 * 用户处理
 * 刘柱
 * 20181230 0623
 */
@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;


    @Override
    public ApiResult login(UserInfo userInfo) {
        UserInfo result = userMapper.getUserInfo(userInfo.getUserName().trim());
        if (result == null) {
            return new ApiResult().failure(AppContent.LOGIN_USERNAME_ISNOTEXIST, "登录失败，用户名不存在");
        }
        String encriptMd5Password = MD5Utils.getMD5String(userInfo.getPassword());
        if (!encriptMd5Password.equals(result.getPassword())) {
            return new ApiResult().failure(AppContent.LOGIN_PASSWORD_ERROR, "登录失败，密码错误");
        }

        return new ApiResult().success(AppContent.LOGIN_SUCC, "登录成功");
    }
}
